package com.godofgamblers.hotelmanagementsystem.service.imp;

import com.godofgamblers.hotelmanagementsystem.mapper.OrderItemMapper;
import com.godofgamblers.hotelmanagementsystem.mapper.Room_typeMapper;
import com.godofgamblers.hotelmanagementsystem.pojo.BookedCount;
import com.godofgamblers.hotelmanagementsystem.pojo.RoomCount;
import com.godofgamblers.hotelmanagementsystem.service.BackHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*

@author huanglang

@create_time 2019-10-17 09:37

Nothing is difficult but bugs

*/
@Service
public class BackHomeServiceImp implements BackHomeService {
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private Room_typeMapper roomTypeMapper;

    @Override
    public List<RoomCount> getRoomsStockOfDay(String day) {
        //获得房间标准库存
        List<RoomCount> roomsStock = roomTypeMapper.getRoomsCountByDay();
        //获得实际入住数
        List<BookedCount> bookedCounts = orderItemMapper.getBookedCounts(day);
        for (int i = 0; i < bookedCounts.size(); i++) {
            int id = bookedCounts.get(i).getRoom_type_id()-1;
            int stock = roomsStock.get(id).getRoom_count() - bookedCounts.get(i).getBooked();
            //计算后库存
            roomsStock.get(id).setRoom_count(stock);
        }
        return roomsStock;
    }
}
